package com.xinsoft.entity.dto;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.xinsoft.constant.Const;
import com.xinsoft.entity.po.MesBom;
import com.xinsoft.entity.po.MesProducePlan;
import com.xinsoft.entity.vo.ErpProductionPlanVO;
import com.xinsoft.utils.RedisUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author: π
 * 生产计划 ----对应金蝶的 生产任务单
 * */
@Data
public class KisProductionPlanDto {

    // 单据明细
    private Long     craftId;    //工艺路线的主键
    private String  FConfirmDate;   //单据确认日期:"
    private String  FOrderInterID;  //销售订单号:"
    private String  FCheckDate;     //制单日期:"
    private String  FInterId;       //主键
    private String  FBillNo ;        //编码
    private String  FItemID;        //物料代码："
    private String  FUnitID;        //单    位:"
    private String  FGMPBatchNo;     //批    号:"
    private String  FCostObjID;      //成本对象:"
    private String  FWorktypeID;     //生产类型:"
    private String  FBomInterID;     //BOM 编号:"
    private String  FRoutingID;      //工艺路线:"
    private String  Fauxqty;         //计划生产数量:"
    private String  FInHighLimit;    //完工入库超收比例(%):"
    private String  FAuxInHighLimitQty;     //完工入库上限:"
    private String  FWorkShop;       //生产车间:"
    private String  FInLowLimit;     //完工入库欠收比例(%):"
    private String  FAuxInLowLimitQty;     //完工入库下限:"
    private String  FPlanCommitDate;       //计划开工日期:"
    private String  FPlanFinishDate;       //计划完工日期:"
    private String  FMRP;      //单据来源:"
    private String  Fnote;     //备    注:"
    private String  FProductionLineID;     //生 产 线:"
    private String  Fstatus;         //单据状态:"
    private String  FCommitDate;     //单据下达日期:"
    private String  FBillerID;       //制 单 人:"
    private String  FStartDate;      //实际开工日期:"
    private String  FMultiCheckDate1;    //一审日期:"
    private String  FSourceEntryID;      //源单行号:"
    private String  FPPOrderInterID;     //生产预测单号:"
    private String  FPlanOrderInterID;   //计划订单号"
    private String  FChangeTimes;     //变更次数:"
    private String  FScheduleID;     //上级重复生产计划单号"
    private String  FType;     //生产类型属性:"
    private String  FCommitQty;     //计划完工数量:"
    private String  FProcessPrice;     //加工单价:"
    private String  FCustID;     //委托加工单位:"
    private String  FAuxQtyLost;     //遗失数量:"
    private String  FMultiCheckLevel1;     //一审:"
    private String  FMultiCheckLevel3;     //三审:"
    private String  FMultiCheckLevel2;     //二审:"
    private String  FMultiCheckLevel4;     //四审:"
    private String  FPlanIssueDate;        //计划发料日期:"
    private String  FFinishDate;           //实际完工日期:"
    private String  FSupplyID;             //加工单位:"
    private String  FProcessFee;           //加工费用:"
    private String  FMultiCheckLevel5;     //五审:"
    private String  FMultiCheckLevel6;     //六审:"
    private String  FAuxStockQty;     //入库数量:"
    private String  FAuxQtyFinish;     //实作数量:"
    private String  FAuxQtyPass;     //合格数量:"
    private String  FAuxQtyScrap;     //因工报废数量:"
    private String  FAuxQtyForItem;     //因料报废数量:"
    private String  FConfirmerID;     //确认人:"
    private String  FCheckerID;     //结 案 人:"
    private String  FParentInterID;     //上级任务单号:"
    private String  FConveyerID;     //下 达 人:"
    private String  FFinishTime;     //人工实作工时:"
    private String  FReadyTime;     //机台准备工时:"
    private String  FFixTime;     //机台实作工时:"
    private String  FMrpLockFlag;     //MRP计算标记"
    private String  FCloseDate;     //结案日期:"
    private String  FPlanMode;     //计划模式:"
    private String  FMtoNo;     //计划跟踪号:"
    private String  FPlanConfirmed;     //计划确认:"
    private String  FPrintCount;     //打印次数:"
    private String  FCardClosed;     //流转卡关联关闭:"
    private String  FHRReadyTime;     //人工准备工时:"
    private String  FFinClosed;     //财务结算标志:"
    private String  FFinCloseer;     //财务结算人:"
    private String  FFinClosedate;     //财务结算日期:"
    private String  FHeadSelfJ0187;     //客户名称:"
    private String  FStockFlag;     //领料标识:"
    private String  FHeadSelfJ0188;     //电镀要求:"
    private String  FHeadSelfJ0189;     //客户要求:"
    private String  FSourceTranType;     //源单类型:"
    private String  FSourceInterId;     //源单内码:"
    private String  FHeadSelfJ0190;     //包装要求:"
    private String  FHeadSelfJ0191;     //注意事项:"
    private String  FSourceBillNo;     //源单单号:"
    private String  FHeadSelfJ0192;     //下单员:"
    private String  FHeadSelfJ0194;     //交货日期:"
    private String  FHeadSelfJ0195;     //产品类别:"
    private String  FCOLUMNNAME;     //FHeadSelfJ0196",
    private String  FHeadSelfJ0196;     //颜色:"
    private String  FHeadSelfJ01100;     //物料类别："
    private String  FHeadSelfJ01101;     //自定义项101"



    private RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);

    public  MesProducePlan voToPo(KisProductionPlanDto dto) {
        MesProducePlan vo = new MesProducePlan();
        vo.setId(new Integer(dto.getFInterId()));
        vo.setSourceId(ObjectUtil.isNotEmpty(dto.getFOrderInterID()) ? new Integer(dto.getFOrderInterID()) : new Integer(dto.getFSourceInterId()));
        vo.setSourceCode(dto.getFSourceBillNo());
        vo.setSourceType(vo.getSourceId().equals(0) ? null : 10732);
        vo.setPlanNo(dto.getFBillNo());
        vo.setMaterialId(new Integer((dto.getFItemID())));
        vo.setDeptId(new Integer(dto.getFWorkShop()));
        vo.setProduceType(10681);
        vo.setPlanNum(new BigDecimal(dto.getFauxqty()));
        vo.setBatchNo(dto.getFGMPBatchNo());
        vo.setPlanStartTime(ObjectUtil.isEmpty(dto.getFPlanCommitDate()) ? null : DateUtil.parse(dto.getFPlanCommitDate(), redisUtil.get(Const.TIME_FORMAT).toString()));
        vo.setPlanEndTime(ObjectUtil.isEmpty(dto.getFPlanFinishDate()) ? null : DateUtil.parse(dto.getFPlanFinishDate(),redisUtil.get(Const.TIME_FORMAT).toString()));
        vo.setBomId(new Integer((dto.getFBomInterID())));
        vo.setCompletionMax(new BigDecimal(dto.getFAuxInHighLimitQty()));
        vo.setCompletionMin(new BigDecimal(dto.getFAuxInLowLimitQty()));
        vo.setClientName(dto.getFHeadSelfJ0187());
        vo.setPlanStatus(1);
        vo.setAuditStatus(1);
        vo.setAuditId(ObjectUtil.isNotEmpty(dto.getFConfirmerID()) ? new Integer(dto.getFOrderInterID()) : new Integer(dto.getFConfirmerID()));
        vo.setDeliveryDate(ObjectUtil.isEmpty(dto.getFPlanFinishDate()) ? null : DateUtil.parse(dto.getFPlanFinishDate(),redisUtil.get(Const.TIME_FORMAT).toString()));
        //下达时间/
        vo.setReleaseTime(ObjectUtil.isEmpty(dto.getFCommitDate()) ? null : DateUtil.parse(dto.getFCommitDate(),redisUtil.get(Const.TIME_FORMAT).toString()));
        //结案时间
        vo.setActualFinishTime(ObjectUtil.isEmpty(dto.getFCloseDate()) ? null : DateUtil.parse(dto.getFCloseDate(),redisUtil.get(Const.TIME_FORMAT).toString()));
        //审核人 ----> 确认人
        vo.setReleasePersonId(StringUtils.isNotBlank(dto.getFConfirmerID()) ? new Integer(dto.getFConfirmerID()) : 0);
        //制单人 ----> 下达人
        vo.setCreateBy(StringUtils.isNotBlank(dto.getFConveyerID()) ? new Integer(dto.getFConveyerID()) : 0);
        //创建时间
        vo.setCreateTime(ObjectUtil.isEmpty(dto.getFCheckDate()) ? null : DateUtil.parse(dto.getFCheckDate(),redisUtil.get(Const.TIME_FORMAT).toString()));
        //更新时间 ----->  单据确认日期 ***
        vo.setUpdateTime(ObjectUtil.isEmpty(dto.getFConfirmDate()) ? null : DateUtil.parse(dto.getFConfirmDate(),redisUtil.get(Const.TIME_FORMAT).toString()));
        vo.setDoDelete(0);
        return vo;
    }


//    {
//      \"BillHead\": {
//        \"FBrNo\": \"0\",
//        \"FInterID\": \"8199\",
//        \"FBillNo\": \"WORK007197\",
//        \"FTranType\": \"85\",
//        \"FStatus\": \"1\",
//        \"FMRP\": \"11077\",
//        \"FType\": \"1054\",
//        \"FWorkShop\": \"4078\",
//        \"FItemID\": \"2853\",
//        \"FQty\": \"150.0000000000\",
//        \"FCommitQty\": \"150.0000000000\",
//        \"FPlanCommitDate\": \"7/15/2023 12:00:00 AM\",
//        \"FPlanFinishDate\": \"8/15/2023 12:00:00 AM\",
//        \"FConveyerID\": \"16427\",
//        \"FCommitDate\": \"7/14/2023 12:00:00 AM\",
//        \"FCheckerID\": \"\",
//        \"FCheckDate\": \"12/15/2020 12:00:00 AM\",
//        \"FRequesterID\": \"\",
//        \"FBillerID\": \"16404\",
//        \"FSourceEntryID\": \"4\",
//        \"FClosed\": \"0\",
//        \"FNote\": \"\",
//        \"FUnitID\": \"1413\",
//        \"FAuxCommitQty\": \"150.0000000000\",
//        \"FAuxQty\": \"150.0000000000\",
//        \"FOrderInterID\": \"3578\",
//        \"FPPOrderInterID\": \"0\",
//        \"FParentInterID\": \"0\",
//        \"FCancellation\": \"False\",
//        \"FSupplyID\": \"0\",
//        \"FQtyFinish\": \"0.0000000000\",
//        \"FQtyScrap\": \"0.0000000000\",
//        \"FQtyForItem\": \"0.0000000000\",
//        \"FQtyLost\": \"0.0000000000\",
//        \"FPlanIssueDate\": \"\",
//        \"FRoutingID\": \"0\",
//        \"FStartDate\": \"\",
//        \"FFinishDate\": \"\",
//        \"FAuxQtyFinish\": \"0.0000000000\",
//        \"FAuxQtyScrap\": \"0.0000000000\",
//        \"FAuxQtyForItem\": \"0.0000000000\",
//        \"FAuxQtyLost\": \"0.0000000000\",
//        \"FMrpClosed\": \"0\",
//        \"FBomInterID\": \"1667\",
//        \"FQtyPass\": \"0.0000000000\",
//        \"FAuxQtyPass\": \"0.0000000000\",
//        \"FQtyBack\": \"0.0000000000\",
//        \"FAuxQtyBack\": \"0.0000000000\",
//        \"FFinishTime\": \"0.0000000000\",
//        \"FReadyTIme\": \"0.0000000000\",
//        \"FPowerCutTime\": \"0.0000000000\",
//        \"FFixTime\": \"0.0000000000\",
//        \"FWaitItemTime\": \"0.0000000000\",
//        \"FWaitToolTime\": \"0.0000000000\",
//        \"FTaskID\": \"0\",
//        \"FWorkTypeID\": \"55\",
//        \"FCostObjID\": \"2854\",
//        \"FStockQty\": \"150.0000000000\",
//        \"FAuxStockQty\": \"150.0000000000\",
//        \"FSuspend\": \"False\",
//        \"FProjectNO\": \"0\",
//        \"FProductionLineID\": \"0\",
//        \"FReleasedQty\": \"0.0000000000\",
//        \"FReleasedAuxQty\": \"0.0000000000\",
//        \"FUnScheduledQty\": \"0.0000000000\",
//        \"FUnScheduledAuxQty\": \"0.0000000000\",
//        \"FSubEntryID\": \"0\",
//        \"FScheduleID\": \"0\",
//        \"FPlanOrderInterID\": \"784908\",
//        \"FProcessPrice\": \"0.0000000000\",
//        \"FProcessFee\": \"0.0000000000\",
//        \"FGMPBatchNo\": \"I.O.:补料\",
//        \"FGMPCollectRate\": \"0.0000000000\",
//        \"FGMPItemBalance\": \"0.0000000000\",
//        \"FGMPBulkQty\": \"0.0000000000\",
//        \"FCustID\": \"0\",
//        \"FMultiCheckLevel1\": \"\",
//        \"FMultiCheckLevel2\": \"\",
//        \"FMultiCheckLevel3\": \"\",
//        \"FMultiCheckLevel4\": \"\",
//        \"FMultiCheckLevel5\": \"\",
//        \"FMultiCheckLevel6\": \"\",
//        \"FMultiCheckDate1\": \"\",
//        \"FMultiCheckDate2\": \"\",
//        \"FMultiCheckDate3\": \"\",
//        \"FMultiCheckDate4\": \"\",
//        \"FMultiCheckDate5\": \"\",
//        \"FMultiCheckDate6\": \"\",
//        \"FCurCheckLevel\": \"\",
//        \"FMRPLockFlag\": \"0\",
//        \"FHandworkClose\": \"0\",
//        \"FConfirmerID\": \"16427\",
//        \"FConfirmDate\": \"7/14/2023 12:00:00 AM\",
//        \"FInHighLimit\": \"0.0000000000\",
//        \"FInHighLimitQty\": \"150.0000000000\",
//        \"FAuxInHighLimitQty\": \"150.0000000000\",
//        \"FInLowLimit\": \"0.0000000000\",
//        \"FInLowLimitQty\": \"150.0000000000\",
//        \"FAuxInLowLimitQty\": \"150.0000000000\",
//        \"FChangeTimes\": \"0\",
//        \"FCheckCommitQty\": \"0.0000000000\",
//        \"FAuxCheckCommitQty\": \"0.0000000000\",
//        \"FCloseDate\": \"\",
//        \"FPlanConfirmed\": \"1\",
//        \"FPlanMode\": \"14036\",
//        \"FMTONo\": \"\",
//        \"FPrintCount\": \"0\",
//        \"FFinClosed\": \"0\",
//        \"FFinCloseer\": \"0\",
//        \"FFinClosedate\": \"\",
//        \"FStockFlag\": \"14216\",
//        \"FStartFlag\": \"0\",
//        \"FVchBillNo\": \"\",
//        \"FVchInterID\": \"0\",
//        \"FCardClosed\": \"1059\",
//        \"FHRReadyTime\": \"0.0000000000\",
//        \"FSourceTranType\": \"0\",
//        \"FSourceInterId\": \"0\",
//        \"FSourceBillNo\": \"\",
//        \"FHeadSelfJ0187\": \"\",
//        \"FHeadSelfJ0188\": \"0.0000000000\",
//        \"FHeadSelfJ0189\": \"150.0000000000\",
//        \"FHeadSelfJ0190\": \"0\",
//        \"FConnectFlag\": \"0\"
//    }
}
